﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

using DataSync.DAL;
using IBM.Data.DB2;

namespace DataSync.Model
{
    /// <summary>
    /// 实体类基类，所有实体类都继承自此类
    /// </summary>
    public abstract class SyncBase
    {
        private string sourceTableName;
        private string targetTableName;
        private string scheme;
        private int syncType;
        private string sourceIdFieldName;
        private string targetIdFieldName;
        private string sourceDateFieldName;
        private string targetDateFieldName;
        private string filterString = "";
        private SqlBulkCopy bulkCopy = null;
        private bool isSubTable = false;
        private bool isCustomerSync = false;
        private bool isFullSyncByDay = false;

        /// <summary>
        /// 全量同步是否按天同步，false是按月同步，true是按天同步
        /// </summary>
        public bool IsFullSyncByDay
        {
            get { return isFullSyncByDay; }
            set { isFullSyncByDay = value; }
        }

        /// <summary>
        /// 是否是自定义同步
        /// </summary>
        public bool IsCustomerSync
        {
            get { return isCustomerSync; }
            set { isCustomerSync = value; }
        }

        /// <summary>
        /// 是否是分表
        /// </summary>
        public bool IsSubTable
        {
            get { return isSubTable; }
            set { isSubTable = value; }
        }

        public SqlBulkCopy BulkCopy
        {
            get { return bulkCopy; }
            set { bulkCopy = value; }
        }

        /// <summary>
        /// 源数据表名称
        /// </summary>
        public string SourceTableName
        {
            get { return sourceTableName; }
            set { sourceTableName = value; }
        }

        /// <summary>
        /// 目标数据表名称
        /// </summary>
        public string TargetTableName
        {
            get { return targetTableName; }
            set { targetTableName = value; }
        }

        /// <summary>
        /// 模式名称
        /// </summary>
        public string Scheme
        {
            get { return scheme; }
            set { scheme = value; }
        }

        /// <summary>
        ///同步类型，完全同步（0），按日期同步（1），按自增ID同步（2）
        /// </summary>
        public int SyncType
        {
            get { return syncType; }
            set { syncType = value; }
        }

        /// <summary>
        /// 源数据库中自增ID字段名称
        /// </summary>
        public string SourceIdFieldName
        {
            get { return sourceIdFieldName; }
            set { sourceIdFieldName = value; }
        }

        public string TargetIdFieldName
        {
            get { return targetIdFieldName; }
            set { targetIdFieldName = value; }
        }

        /// <summary>
        /// 源数据库中自增日期字段名称
        /// </summary>
        public string SourceDateFieldName
        {
            get { return sourceDateFieldName; }
            set { sourceDateFieldName = value; }
        }

        /// <summary>
        /// 目标数据中自增日期字段名称
        /// </summary>
        public string TargetDateFieldName
        {
            get { return targetDateFieldName; }
            set { targetDateFieldName = value; }
        }

        /// <summary>
        /// 额外筛选字符串，如Charge_Status IN (0,110,120)
        /// </summary>
        public string FilterString
        {
            get { return filterString; }
            set { filterString = value; }
        }

        #region OLD
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="reader"></param>
        //public abstract void Export(SqlDataReader reader);

        ///// <summary>
        ///// 插入到SQL数据库
        ///// </summary>
        ///// <param name="max">返回实际导入的最大ID或日期</param>
        ///// <param name="sqlHelper">SQL工具类</param>
        ///// <returns>返回执行SQL语句所影响的行数</returns>
        //public abstract int Insert(out object max, SQLHelper sqlHelper); 
        #endregion
    }
}
